package top.shiyiri.i18n;

import org.junit.Test;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 * @author Aunean
 * @date 2022/2/12 22:06
 */
public class I18nTest {

    @Test
    public void testLocal() {
        //获取系统默认的语言。国家信息
//        Locale locale = Locale.getDefault();
//        System.out.println(locale);
//        for (Locale availableLocal : Locale.getAvailableLocales()) {
//            System.out.println(availableLocal);
//        }

        //获取中文，中文的常量的Locale对象
        System.out.println(Locale.CHINA);
        //获取英文，美国的常量的Locale对象
        System.out.println(Locale.US);
    }

    @Test
    public void testI18n() {
//        Locale locale = Locale.US;
        Locale locale = Locale.CHINA;
        //通过指定的basename和Locale对象，读取相应的配置文件
        ResourceBundle bundle = ResourceBundle.getBundle("i18n", locale);
        String username = bundle.getString("username");
        System.out.println("用户名：" + username);
        String password = bundle.getString("password");
        System.out.println("密码：" + password);

    }
}
